package cn.outsourcing.supermarket.converter;

import cn.outsourcing.supermarket.converter.transform.TimestampTransform;
import cn.outsourcing.supermarket.po.HiolabsUser;
import cn.outsourcing.supermarket.vo.UserDetailVO;
import cn.outsourcing.supermarket.vo.backstage.BackstageUserListVO;
import cn.outsourcing.supermarket.vo.hiolabs.HiolabsUserVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 用户转化器
 *
 * @author gzkemays
 * @since 2021/10/25 18:22
 */
@Mapper(uses = {TimestampTransform.class})
public interface HiolabsUserConverter {
  HiolabsUserConverter INSTANCE = Mappers.getMapper(HiolabsUserConverter.class);

  /**
   * 返回用户配置信息
   *
   * @param user 原 po 对象
   * @return 配置信息值对象
   */
  UserDetailVO convertToUserDetail(HiolabsUser user);

  /**
   * 转化为自身值对象
   *
   * @param user 原 po 类
   * @return 自身值对象
   */
  @Mappings({
    @Mapping(
        expression =
            "java(cn.outsourcing.supermarket.common.utils.StrUtils.getStrByBase64(user.getNickname()))",
        target = "nickname")
  })
  HiolabsUserVO convertToVo(HiolabsUser user);

  /**
   * 转化为自身列表值对象
   *
   * @param user 原 po 类
   * @return 列表值对象
   */
  List<HiolabsUserVO> convertToVoList(List<HiolabsUser> user);

  /**
   * 转换为后台列表值对象
   *
   * @param user 原 po 类
   * @return 后台列表值对象
   */
  @Mappings({
    @Mapping(
        target = "nickname",
        expression =
            "java(cn.outsourcing.supermarket.common.utils.StrUtils.getStrByBase64(user.getNickname()))"),
    @Mapping(target = "username", source = "user.name"),
    @Mapping(
        target = "balance",
        expression =
            "java(cn.outsourcing.supermarket.converter.transform.BalanceTransform.transformBalance(user.getBalance()))")
  })
  BackstageUserListVO convertToBackstageUserVo(HiolabsUser user);
  /**
   * 转换为后台列表值对象 list
   *
   * @param user 原 po 类
   * @return 后台列表值对象 list
   */
  List<BackstageUserListVO> convertToBackstageUserVoList(List<HiolabsUser> user);
}
